package com.younge.spring.api.common;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Page;

import java.util.List;

@Setter
@Getter
public class PageResult<T> {
    private List<T> items; //数据列表
    private long total; // 总记录数
    private long pageSize; // 页大小
    private long current; // 当前页

    public static <T> PageResult<T> of(Page<T> page) {
        PageResult<T> response = new PageResult<>();
        response.setItems(page.getContent());
        response.setTotal(page.getTotalElements());
        response.setPageSize(page.getSize());
        response.setCurrent(page.getNumber());
        return response;
    }

}
